package subraSoft.fenix.gui;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.UIManager;

import subraSoft.centaurus.gui.CenApplication;
import subraSoft.centaurus.login.CenLogin;
import subraSoft.centaurus.model.util.CenHibernateUtil;
import subraSoft.fenix.model.authentication.cobj.FenObjSecCObj;
import subraSoft.fenix.model.authentication.service.FenObjSecService;
import subraSoft.fenix.model.authentication.service.impl.FenObjSecServiceImpl;


public class FenApplication extends CenApplication
{
	
	private Set<String> res = null;
	
	/**
	 * Lanza la interfaz grafica.
	 * 
	 * @param args no se esperan parametros	
	 */
	public static void main(String [] args)
	{
		try 
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} 
		catch (Exception ex) 
		{
			new RuntimeException("Error: " + ex);
		}
		
		FenApplication gui = new FenApplication();
		
		CenLogin c = new FenLogin();
		c.create();

		gui.create();
		if(isSplashEnabled())
			gui.createSplash(1000);
		CenHibernateUtil.getInstance().getSessionFactory(); // TODO
	}
	
	
	private static boolean isSplashEnabled()
	{
		return true;
	}

	@Override
	protected String getAppTitle() 
	{
		return "Fenix";
	}


	@Override
	public Set<String> getPermisos() 
	{
		if(res == null)
		{
			res = new HashSet<String>();
			
			FenObjSecService service = new FenObjSecServiceImpl();
			List<FenObjSecCObj> list = service.getObjetosSeguidad(getUser());
			for (FenObjSecCObj fenObjSecCObj : list) {
				res.add((String)fenObjSecCObj.getId());
				System.out.println((String)fenObjSecCObj.getId());
			}
		}
		
		return res;
	}
}
